package com.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.objects.GroupMember;
import com.senditcertified.mail.R;

public class GroupMemberAdapter extends BaseAdapter implements OnClickListener {
	private Context mContext;
	private ArrayList<GroupMember> lst;
	private LayoutInflater inflater = null;

	public GroupMemberAdapter(Context mContext, ArrayList<GroupMember> lst) {
		this.mContext = mContext;
		this.lst = lst;
		this.inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}
	public void checkHas(long iD){
		
	}
	public int getCount() {
		if (lst == null)
			return 0;
		else
			return lst.size();
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		GroupMember item = getItem(position);
		if (convertView == null) {
			v = inflater.inflate(R.layout.item_edit_group_member, null);
		}
		TextView tvFirstName = (TextView) v.findViewById(R.id.tv_first_name);
		TextView tvLastName = (TextView) v.findViewById(R.id.tv_last_name);
		TextView tvEmail = (TextView) v.findViewById(R.id.tv_email);
		TextView tvAction = (TextView) v.findViewById(R.id.tv_action);

		tvFirstName.setText(item.getFirstName());
		tvLastName.setText(item.getLastName());
		tvEmail.setText(item.getEmail());
		tvAction.setTag(position);
		tvAction.setOnClickListener(this);

		tvLastName.setSelected(true);
		tvFirstName.setSelected(true);
		tvEmail.setSelected(true);
		tvAction.setSelected(true);

		return v;
	}

	public void onViewEdit(int pos) {

	}

	@Override
	public void onClick(View v) {
		onViewEdit(Integer.parseInt(v.getTag().toString()));
	}

	@Override
	public GroupMember getItem(int arg0) {
		return lst.get(arg0);
	}

}